<!-- 毛坯仓收货 -->
<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form isheader" v-if="headerShow">
        <div>
          <a-form size="small" :model="pageData" layout="inline">
            <a-form-item label="来源单号">
              <a-input allow-clear :style="{ width: '200px' }" class="bacClass" v-model="pageData.sourceCode"/>
            </a-form-item>
            <a-form-item label="客户名称">
              <a-input allow-clear :style="{ width: '200px' }" class="bacClass" v-model="pageData.customName"/>
            </a-form-item>
            <a-form-item label="开单日期">
              <a-date-picker popup-container="html" class="bacClass" v-model="pageData.dateStart"/>
            </a-form-item>
            <a-form-item label="至">
              <a-date-picker popup-container="html" class="bacClass" v-model="pageData.dateEnd"/>
            </a-form-item>
          </a-form>
        </div>
        <div style="text-align: end;">
          <Toolbar :items="toolbarList" @reders="addHandler" @select="selectHandler" @del="deleteHandler"
                   @dyBoufei="counters" @audit="audits">
          </Toolbar>
        </div>
      </div>
      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up v-if="headerShow" @click="headerShow = false" :strokeWidth="2" :size="18"/>
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18"/>
        </a-divider>
      </div>
    </template>
    <template #pageTabel>
      <a-tabs   :lazy-load="true" :justify="true" :default-active-key="tabsKeys" @change="tabsChanges">
        <a-tab-pane title="织厂收货" :key="1">
          <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true"
                           rowSelection="multiple" @grid-ready="gridReady"
                           style="height:calc(100% - 45px)" :defaultColDef="defaultColDef" class='ag-theme-alpine'
                           :rowData="tableDataList"
                           :columnDefs="tc" :localeText="localeText1"></AgGridVuesCopys>
          <paginationCopys :page-size-options="pagingList1" :total="total" show-total show-jumper show-page-size
                           @change="PageSize" @page-size-change="change" style="justify-content: center"
                           :page-size="pagination.pageSize" :current="pagination.page"/>
        </a-tab-pane>
        <a-tab-pane title="未审核" :key="3">
          <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true"
                           rowSelection="multiple" @grid-ready="gridReady3"
                           style="height:calc(100% - 45px)" :defaultColDef="defaultColDef3" class='ag-theme-alpine'
                           :rowData="tableDataList3"
                           :columnDefs="tc3" :localeText="localeText1"></AgGridVuesCopys>
          <paginationCopys :page-size-options="pagingList1" :total="total3" show-total show-jumper show-page-size
                           @change="PageSize" @page-size-change="change" style="justify-content: center"
                           :page-size="pagination.pageSize" :current="pagination.page"/>
        </a-tab-pane>
        <a-tab-pane title="已审核" :key="4">
          <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true"
                           rowSelection="multiple" @grid-ready="gridReady4"
                           style="height:calc(100% - 45px)" :defaultColDef="defaultColDef4" class='ag-theme-alpine'
                           :rowData="tableDataList4"
                           :columnDefs="tc4" :localeText="localeText1"></AgGridVuesCopys>
          <paginationCopys :page-size-options="pagingList1" :total="total4" show-total show-jumper show-page-size
                           @change="PageSize" @page-size-change="change" style="justify-content: center"
                           :page-size="pagination.pageSize" :current="pagination.page"/>
        </a-tab-pane>
      </a-tabs>
    </template>
    <a-drawer :drawer-style="{ 'zIndex': 9999 }" :mask-closable="false" height="80%" :visible="pageData.showAdd8"
              unmountOnClose @ok="sideOk" @cancel="pageData.showAdd8 = false" cancel-text='关闭' ok-text='保存'
              placement="bottom">
      <template #title>
        {{ pageData.sideTitle }}
      </template>
      <div style="min-width:800px;">
        <div>
          <a-row :gutter="16">
            <a-col :span="4">
              <a-form-item label="开单日期">
                <a-date-picker popup-container="html" class="bacClass" v-model="objectOP.stocklnDate"/>
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="计件日期">
                <a-date-picker popup-container="html" class="bacClass" v-model="objectOP.reckonPieceDate"/>
              </a-form-item>
            </a-col>
            <a-col :span="4" v-if="pageData.sideTitle != '新增车间退库' && pageData.sideTitle != '修改入库单'">
              <a-form-item label="仓库名称">
                <a-select popup-container="html" class="bacClass" :loading="loading" :allowClear="true"
                          @search="handleSearch"
                          v-model="objectOP.warehouseId" :filter-option="false" allow-search @focus="focusSel"
                          @change="chanON">
                  <a-option v-for="item in pageData.nameList" :value="item['id']">{{
                      item['warehouseName']
                    }}
                  </a-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="4" v-if="pageData.sideTitle == '新增车间退库' || pageData.sideTitle == '修改入库单'">
              <a-form-item label="仓库名称">
                <a-select popup-container="html" disabled class="bacClass" :loading="loading" :allowClear="true"
                          @search="handleSearch"
                          v-model="objectOP.warehouseName" :filter-option="false" allow-search @focus="focusSel"
                          @change="chanON">
                  <a-option v-for="item in pageData.nameList" :value="item['warehouseName']">{{
                      item['warehouseName']
                    }}
                  </a-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="业务员">
                <a-select popup-container="html" class="bacClass" :loading="loading" :allowClear="true"
                          @search="handleSearch1"
                          v-model="objectOP.salesman" :filter-option="false" allow-search @focus="focusSel1">
                  <a-option v-for="item in pageData.nameList1" :value="item['name']">{{
                      item['name']
                    }}
                  </a-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="入库类型">
                <a-input v-model="objectOP.stockInTypeName" disabled class="bacClass"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="客户订单号">
                <a-input disabled class="bacClass" v-model="objectOP.customOrderCode"></a-input>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row :gutter="16">
            <a-col :span="4">
              <a-form-item label="客户名称">
                <a-input disabled class="bacClass" v-model="objectOP.customName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="送货车号">
                <a-input disabled class="bacClass" v-model="objectOP.carPlate"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="送货工">
                <a-input class="bacClass" v-model="objectOP.deliveryPerson"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="送货单位">
                <a-input disabled class="bacClass" v-model="objectOP.deliveryDepartmentName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="加工单位">
                <a-input disabled class="bacClass" v-model="objectOP.processDepartment"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="搬运方式">
                <a-select popup-container="html" class="bacClass" :loading="loading" :allowClear="true"
                          v-model="objectOP.carryTypeName" :filter-option="false" allow-search @focus="focusSel4"
                          @change="change4">
                  <a-option v-for="item in pageData.nameList4" :value="item['carryTypeName']">{{
                      item['carryTypeName']
                    }}
                  </a-option>
                </a-select>
              </a-form-item>
            </a-col>
          </a-row>
          <a-row :gutter="16">
            <a-col :span="4">
              <a-form-item label="重量">
                <a-input disabled class="bacClass" v-model="objectOP.weight"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="匹数">
                <a-input disabled class="bacClass" v-model="objectOP.horseNum"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="计价方式">
                <a-select popup-container="html" class="bacClass" :loading="loading" :allowClear="true"
                          v-model="objectOP.reckonPieceTypeName" :filter-option="false" allow-search>
                  <a-option>重量</a-option>
                  <a-option>长度</a-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="备注">
                <a-input class="bacClass" v-model="objectOP.remark"></a-input>
              </a-form-item>
            </a-col>
            <a-col :span="4">
              <a-form-item label="收货单号">
                <a-input disabled class="bacClass" v-model="objectOP.deliveryCode"></a-input>
              </a-form-item>
            </a-col>
          </a-row>
        </div>
      </div>
      <!-- <div style="height: 100%;"> -->
      <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true"
                       v-if="pageData.sideTitle == '新增织厂送货入库单'" rowSelection="multiple"
                       @grid-ready="gridReady1" style="height:75%" :defaultColDef1="defaultColDef1"
                       class='ag-theme-alpine'
                       :rowData="tableDataList1" :columnDefs="dc" :localeText="localeText1"></AgGridVuesCopys>
      <!-- </div> -->
      <!-- <div style="height: 100%;"> -->
      <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true"
                       v-else-if="pageData.sideTitle == '修改入库单'" rowSelection="multiple"
                       @grid-ready="gridReady3_2" style="height:75%" :defaultColDef3_2="defaultColDef3_2"
                       class='ag-theme-alpine'
                       :rowData="tableDataList3_2" :columnDefs="dc3" :localeText="localeText1"></AgGridVuesCopys>

    </a-drawer>
  </pageTabelLayout>
</template>
<script setup lang="ts">
import {
  useTable,
  useRowKey,
  useTableColumn,
  usePagination,
  useRowSelection,
} from "@/hooks/table";
import {post, get} from "@/api/http"
import {localeText} from '@/api/aggridZw'

import Toolbar from "@/components/Toolbar.vue"
import {Message, Modal} from "@arco-design/web-vue"
import CorporateSectorCascader from '@/components/corporateSectorCascader/inde.vue'
import {FormInstance} from "@arco-design/web-vue/es/form";
import {pagingList} from "@/api/paging";
import dayjs from 'dayjs'
import printJS from 'print-js'
import {ref, reactive, onMounted, onActivated, onUnmounted, nextTick} from "vue";
// const toolbarList: any = ref(['查询', '入库', '删除', '审核', '反审', '打印'])
const toolbarList: any = ref(['查询', '入库'])
let isIDs: any = ref(1);
onMounted(() => {
  // 第一个页面需要在刚进入就调用一次  切换tap时也需要调用
  // doRefresh();
  // selCxAll({});
  // 切换tap到本页面执行的方法
  // emitter.on("DevelopSampleRegistrationListDemo", () => {
  //     // selCxAll({});
  //     doRefresh();
  // });
  pageData.rHeight = document.getElementsByClassName("main-section")[0]?.clientHeight
  //弹出层的高
  if (pageData.rHeight !== undefined) {
    pageData.rHeight = pageData.rHeight - 100;
  }
});

function PageSize(val: any) {
  if (isIDs.value == 1) {
    pagination.page = val
    doRefresh();
  } else if (isIDs.value == 3) {
    pagination3.page = val
    doRefresh3();
  } else if (isIDs.value == 4) {
    pagination4.page = val
    doRefresh4();
  }
}

function change(val: any) {
  if (isIDs.value == 1) {
    pagination.pageSize = val
    doRefresh();
  } else if (isIDs.value == 3) {
    pagination3.pageSize = val
    doRefresh3();
  } else if (isIDs.value == 4) {
    pagination4.pageSize = val
    doRefresh4();
  }
}


const headerShow = ref(true)

const tableDataList = ref([])
const tableDataList1 = ref([])
const tableDataList1_2 = ref([])
const tableDataList3_2 = ref([])
const tableDataList3 = ref([])
const tableDataList4 = ref([])
const tableDataList5_1 = ref([])


const gridOption = ref()
const gridReady = (params: any) => {
  gridOption.value = params.api
}

const gridOption1 = ref()
const gridReady1 = (params: any) => {
  gridOption1.value = params.api
}

const gridOption3_2 = ref()
const gridReady3_2 = (params: any) => {
  gridOption3_2.value = params.api
}
const gridOption3 = ref()
const gridReady3 = (params: any) => {
  gridOption3.value = params.api
}
const gridOption4 = ref()
const gridReady4 = (params: any) => {
  gridOption4.value = params.api
}

const defaultColDef = {
  sortable: true,
  resizable: true,
  filter: true,
}

const defaultColDef1 = {
  sortable: true,
  resizable: true,
  filter: true,
}
const defaultColDef3_2 = {
  sortable: true,
  resizable: true,
  filter: true,
}
const defaultColDef3 = {
  sortable: true,
  resizable: true,
  filter: true,
}
const defaultColDef4 = {
  sortable: true,
  resizable: true,
  filter: true,
}

const localeText1: any = ref(localeText)

const tc = [
  {
    showRowGroup: 'hide_def',
    "headerName": "",
    "checkboxSelection": true,
    "headerCheckboxSelection": true,
    "pinned": "left",
    "width": 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: "left",
  },
  {
    headerName: '出库编号',
    field: 'stockOutCode',
    width: 150,
    filter: 'stockOutCode',
  },
  {
    headerName: '出库时间',
    field: 'stockOutDate',
    width: 150
  },
  {
    headerName: '公司',
    field: 'companyName',
    width: 150
  },
  {
    headerName: '送货单位',
    field: 'deliveryDepartmentName',
    width: 150
  },
  {
    headerName: '车牌号',
    field: 'carPlate',
    width: 150
  },
  {
    headerName: '匹数',
    field: 'horseNum',
    width: 150
  },
  {
    headerName: '重量',
    field: 'weight',
    width: 150
  },
  {
    headerName: '出库仓库',
    field: 'warehouseName',
    width: 150
  },
  {
    headerName: '托盘编号',
    field: 'shelveCode',
    width: 150
  },
  {
    headerName: '布笼名称',
    field: 'shelveName',
    width: 150
  },
  {
    headerName: '备注',
    field: 'remark',
    width: 150
  },
  {
    headerName: '创建人',
    field: 'createName',
    width: 150
  },
  {
    headerName: '创建时间',
    field: 'createTime',
    width: 150
  },
]

const dc = [
  {
    showRowGroup: 'hide_def',
    "headerName": "",
    "checkboxSelection": true,
    "headerCheckboxSelection": true,
    "pinned": "left",
    "width": 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: "left",
  },
  {
    headerName: '出库编号',
    field: 'stockOutCode',
    width: 150,
    filter: 'stockOutCode',
  },
  {
    headerName: '出库时间',
    field: 'stockOutDate',
    width: 150
  },
  {
    headerName: '出库人',
    field: 'stockOutName',
    width: 150
  },
  {
    headerName: '收货单位',
    field: 'shipAddress',
    width: 150
  },
  {
    headerName: '车牌号',
    field: 'carPlate',
    width: 150
  },
  {
    headerName: '客户',
    field: 'customName',
    width: 150
  },
  {
    headerName: '客户订单号',
    field: 'customOrderCode',
    width: 150
  },
  {
    headerName: '坯布编号',
    field: 'greyCode',
    width: 150
  },
  {
    headerName: '坯布名称',
    field: 'greyName',
    width: 150
  },
  {
    headerName: '坯布批号',
    field: 'greyBatchNo',
    width: 150
  },
  {
    headerName: '条码号',
    field: 'clothfiyCode',
    width: 150
  },
  {
    headerName: '品名',
    field: 'brandName',
    width: 150
  },
  {
    headerName: '设备编号',
    field: 'machineCode',
    width: 150
  },
  {
    headerName: '机布号',
    field: 'machineGreyCode',
    width: 150
  },
  {
    headerName: '计划单号',
    field: 'planOrderCode',
    width: 150
  },
  {
    headerName: '原料编号',
    field: 'rawmaterialCode',
    width: 150
  },
  {
    headerName: '原料名称',
    field: 'rawmaterialName',
    width: 150
  },
  {
    headerName: '等级',
    field: 'grade',
    width: 150
  },
  {
    headerName: '匹数',
    field: 'horseNum',
    width: 150
  },
  {
    headerName: '重量',
    field: 'weight',
    width: 150
  },
  {
    headerName: '门幅',
    field: 'width',
    width: 150
  },
  {
    headerName: '针筒',
    field: 'workDrum',
    width: 150
  },
  {
    headerName: '纱批',
    field: 'yarnBatch',
    width: 150
  },
  {
    headerName: '单价',
    field: 'price',
    width: 150
  },
  {
    headerName: '金额',
    field: 'amount',
    width: 150
  },
  {
    headerName: '匹号',
    field: 'horseNo',
    width: 150
  },
  {
    headerName: '流转卡号',
    field: 'circulatCard',
    width: 150
  },
  {
    headerName: '布号',
    field: 'clothCode',
    width: 150
  },
  {
    headerName: '备注',
    field: 'remark',
    width: 150
  },
  {
    headerName: '库位',
    field: 'storageId',
    dataIndex: 'storageId',
    pinned: 'right',
    width: 200,
    cellRenderer: {
      template: `
        <a-select popup-container="html" class="bacClass" :loading="loading" :allowClear="true" @search="handleSearchKW"
                  :filter-option="false" allow-search @focus="focusSelKW" v-model="res.storageId"
                  @change="changes(ress)">
          <a-option v-for="item in pageData.nameListKW" :value="item['id']">{{
              item['storageName']
            }}
          </a-option>
        </a-select>
      `,
      setup(props: any) {
        const res = reactive<{
          storageId: any,
        }>({
          storageId: null,
        })
        const pageData = reactive<{
          nameListKW: any[],
        }>({
          nameListKW: [],
        });

        const focusSelKW = () => {
          selCxAllKW({"warehouseId": objectOP.warehouseId, storageName: ""})
        }
        const optionsKW = ref<any>(pageData.nameListKW);
        const loadingKW = ref(false);
        const handleSearchKW = (value: any) => {
          if (value) {
            const ob = {"warehouseId": objectOP.warehouseId, storageName: value}
            loadingKW.value = true;
            selCxAllKW(ob);
            optionsKW.value = pageData.nameListKW;
            loadingKW.value = false;
          } else {
            optionsKW.value = []
          }
        };

        function selCxAllKW(val: any) {
          if (objectOP.warehouseId == '') {
            Message.error({
              content: "请先选择上方仓库名称！",
              duration: 5000,
            });
          } else {
            post({
              url: "/dwWms/Storage/getFieldValue",
              data: val
            }).then(({data, code}: any) => {
              if (code === 200) {
                pageData.nameListKW = data;


              } else {
                Message.error({
                  content: "查询失败！",
                  duration: 5000,
                });
              }
            });
          }

        }

        const changes = (ress: any) => {
          props.params.data.storageId = res.storageId
          post({
            url: "/dwWms/Storage/getStorageByPara",
            data: {id: res.storageId}
          }).then(({data, code}: any) => {
            if (code === 200) {
              props.params.data.areaId = data[0].areaId;
            } else {
              Message.error({
                content: "查询失败！",
                duration: 5000,
              });
            }

          });
        }

        return {
          changes,
          res,
          pageData,
          reactive,
          selCxAllKW,
          focusSelKW,
          handleSearchKW
        }
      }
    }
  },
  {
    headerName: '托盘编号',
    // field: 'shelveId',
    // dataIndex: 'shelveId',
    field: 'shelveCode',
    dataIndex: 'shelveCode',
    pinned: 'right',
    width: 150,

  }


];

const dc3 = [
  {
    showRowGroup: 'hide_def',
    "headerName": "",
    "checkboxSelection": true,
    "headerCheckboxSelection": true,
    "pinned": "left",
    "width": 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: "left",
  },
  {
    headerName: '计划单号',
    field: 'planOrderCode',
    width: 150,
  },
  {
    headerName: '织造序号',
    field: 'weaveCode',
    width: 150
  },
  {
    headerName: '品名',
    field: 'brandName',
    width: 150
  },
  {
    headerName: '色号',
    field: 'colorCode',
    width: 150
  },
  {
    headerName: '色称',
    field: 'colorName',
    width: 150
  },
  {
    headerName: '坯布编号',
    field: 'greyCode',
    width: 150
  },
  {
    headerName: '坯布名称',
    field: 'greyName',
    width: 150,
  },
  {
    headerName: '匹号',
    field: 'horseNo',
    width: 150
  },
  {
    headerName: '单位',
    field: 'unit',
    width: 150
  },
  {
    headerName: '等级',
    field: 'grade',
    width: 150
  },
  {
    headerName: '条码号',
    field: 'clothfiyCode',
    width: 150
  },
  {
    headerName: '尺寸',
    field: 'inch',
    width: 150
  },
  {
    headerName: '重量',
    field: 'weight',
    width: 150
  },
  {
    headerName: '单价',
    field: 'price',
    width: 150,
  },
  {
    headerName: '门幅',
    field: 'width',
    width: 150
  },
  {
    headerName: '金额',
    field: 'amount',
    width: 150
  },
  {
    headerName: '克重',
    field: 'gramWeight',
    width: 150
  },
  {
    headerName: '区域',
    field: 'areaName',
    width: 150
  },
  {
    headerName: '纱批',
    field: 'yarnBatch',
    width: 150
  },
  {
    headerName: '流转卡号',
    field: 'circulatCard',
    width: 150
  },
  {
    headerName: '布号',
    field: 'clothCode',
    width: 150
  },
  {
    headerName: '备注',
    field: 'remark',
    width: 150
  },
  {
    headerName: '库位',
    field: 'storageId',
    dataIndex: 'storageId',
    pinned: 'right',
    width: 200,
    cellRenderer: {
      template: `

        <a-select popup-container="html" class="bacClass" :loading="loading" :allowClear="true" @search="handleSearchKW"
                  :filter-option="false" allow-search @focus="focusSelKW" v-model="mydata.storageId"
                  @change="changes(ress)">
          <a-option :value="mydata.storageId">{{ mydata.storageName }}</a-option>
          <a-option v-for="item in pageData.nameListKW" :value="item['id']">{{
              item['storageName']
            }}
          </a-option>
        </a-select>
      `,
      setup(props: any) {
        // console.log(props.params.data, '11111111111');

        const mydata = ref(props.params.data);


        const res = reactive<{
          storageId: any,
        }>({
          storageId: null,
        })
        const pageData = reactive<{
          nameListKW: any[],
        }>({
          nameListKW: [],
        });
        // 库位下拉框事件
        const focusSelKW = () => {
          selCxAllKW({"warehouseId": objectOP.warehouseId, storageName: ""})
          // console.log(pageData.nameListKW)
        }
        const optionsKW = ref<any>(pageData.nameListKW);
        const loadingKW = ref(false);
        const handleSearchKW = (value: any) => {
          if (value) {
            const ob = {"warehouseId": objectOP.warehouseId, storageName: value}
            loadingKW.value = true;
            selCxAllKW(ob);
            optionsKW.value = pageData.nameListKW;
            loadingKW.value = false;
          } else {
            optionsKW.value = []
          }
        };

        function selCxAllKW(val: any) {
          if (objectOP.warehouseId == '') {
            Message.error({
              content: "请先选择上方仓库名称！",
              duration: 5000,
            });
          } else {
            post({
              url: "/dwWms/Storage/getFieldValue",
              data: val
            }).then(({data, code}: any) => {
              if (code === 200) {
                pageData.nameListKW = data;


              } else {
                Message.error({
                  content: "查询失败！",
                  duration: 5000,
                });
              }
            });
          }

        }

        const changes = (ress: any) => {
          props.params.data.storageId = res.storageId
          post({
            url: "/dwWms/Storage/getStorageByPara",
            data: {id: res.storageId}
          }).then(({data, code}: any) => {
            if (code === 200) {
              props.params.data.areaId = data[0].areaId;
            } else {
              Message.error({
                content: "查询失败！",
                duration: 5000,
              });
            }

          });
        }

        return {
          changes,
          res,
          pageData,
          reactive,
          selCxAllKW,
          focusSelKW,
          handleSearchKW,
          mydata
        }
      }
    }
  },
  {
    headerName: '托盘编号',
    // field: 'shelveId',
    // dataIndex: 'shelveId',
    field: 'shelveCode',
    dataIndex: 'shelveCode',
    pinned: 'right',
    width: 200,

  }

];
const tc3 = [
  {
    showRowGroup: 'hide_def',
    "headerName": "",
    "checkboxSelection": true,
    "headerCheckboxSelection": true,
    "pinned": "left",
    "width": 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: "left",
  },
  {
    headerName: '入库单号',
    field: 'stockInCode',
    width: 150,
  },
  {
    headerName: '入库日期',
    field: 'stockInDate',
    width: 150
  },
  {
    headerName: '收料单号',
    field: 'deliveryCode',
    width: 150
  },
  {
    headerName: '计件日期',
    field: 'reckonPieceDate',
    width: 150
  },
  {
    headerName: '公司',
    field: 'companyName',
    width: 150
  },
  {
    headerName: '仓库',
    field: 'warehouseName',
    width: 150,
  },
  {
    headerName: '业务员',
    field: 'salesman',
    width: 150
  },
  {
    headerName: '入库类型',
    field: 'stockInTypeName',
    width: 150
  },
  {
    headerName: '送货车号',
    field: 'carPlate',
    width: 150
  },
  {
    headerName: '送货工',
    field: 'deliveryPerson',
    width: 150
  },
  {
    headerName: '送货单位',
    field: 'deliveryDepartmentName',
    width: 150,
  },
  {
    headerName: '加工单位',
    field: 'processDepartment',
    width: 150
  },
  {
    headerName: '搬运方式',
    field: 'carryTypeName',
    width: 150
  },
  {
    headerName: '计件方式',
    field: 'reckonPieceTypeName',
    width: 150
  },
  {
    headerName: '备注',
    field: 'remark',
    width: 150
  },
  {
    headerName: '状态',
    field: 'infoState',
    pinned: 'right',
    width: 150,
    cellRenderer: {
      template: `
        <a-space>
          <el-tag type="success" class="gesture">未审核</el-tag>
        </a-space>
      `,
      setup(props: any) {
        return {
          auditState: props.params.data.auditState,
          barcodeState: props.params.data.barcodeState
        }
      }
    }
  },
  {
    headerName: '操作',
    field: 'id',
    pinned: 'right',
    width: 150,
    cellRenderer: {
      template: `
        <el-button style="color:#165dff;" @click="a" class="gesture" link>修改</el-button>
      `,
      setup(props: any) {
        const a = () => {
          // if (props.params.data.stockInTypeName == '织厂送货入库') {
          editHandler(props.params.data)
          // }
          // else {
          //     editHandler1(props.params.data)
          // }

        }
        return {
          a
        }
      }
    }
  }

];
const tc4 = [
  {
    showRowGroup: 'hide_def',
    "headerName": "",
    "checkboxSelection": true,
    "headerCheckboxSelection": true,
    "pinned": "left",
    "width": 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: "left",
  },
  {
    headerName: '入库单号',
    field: 'stockInCode',
    width: 150,
  },
  {
    headerName: '入库日期',
    field: 'stockInDate',
    width: 150
  },
  {
    headerName: '收料单号',
    field: 'deliveryCode',
    width: 150
  },
  {
    headerName: '计件日期',
    field: 'reckonPieceDate',
    width: 150
  },
  {
    headerName: '公司',
    field: 'companyName',
    width: 150
  },
  {
    headerName: '仓库',
    field: 'warehouseName',
    width: 150,
  },
  {
    headerName: '业务员',
    field: 'salesman',
    width: 150
  },
  {
    headerName: '入库类型',
    field: 'stockInTypeName',
    width: 150
  },
  {
    headerName: '送货车号',
    field: 'carPlate',
    width: 150
  },
  {
    headerName: '送货工',
    field: 'deliveryPerson',
    width: 150
  },
  {
    headerName: '送货单位',
    field: 'deliveryDepartmentName',
    width: 150,
  },
  {
    headerName: '加工单位',
    field: 'processDepartment',
    width: 150
  },
  {
    headerName: '搬运方式',
    field: 'carryTypeName',
    width: 150
  },
  {
    headerName: '计件方式',
    field: 'reckonPieceTypeName',
    width: 150
  },
  {
    headerName: '备注',
    field: 'remark',
    width: 150
  },
  {
    headerName: '状态',
    field: 'infoState',
    pinned: 'right',
    width: 150,
    cellRenderer: {
      template: `
        <a-space>
          <el-tag type="success" class="gesture">已审核</el-tag>
        </a-space>
      `,
      setup(props: any) {
        return {
          auditState: props.params.data.auditState,
          barcodeState: props.params.data.barcodeState
        }
      }
    }
  },
]

const objectOP = reactive<{
  reckonPieceTypeName: number,
  stocklnDate: any,
  reckonPieceDate: any,
  warehouseName: any,
  warehouseId: any,
  salesman: any,
  stockInTypeName: any,
  customName: any,
  carPlate: any,
  deliveryPerson: any,
  deliveryDepartmentName: any,
  deliveryDepartmentId: any,
  customOrderCode: any,
  processDepartment: any,
  carryTypeName: any,
  horseNum: any,
  weight: any,
  id: any,
  remark: any,
  deliveryCode: any,
  stockInCode: any,
  stockInTypeId: any,
  companyId: any,
  carryTypeId: any,
  BlankStockInDetail: any[],
}>({
  companyId: null,
  stockInTypeId: null,
  reckonPieceTypeName: 0,
  warehouseName: '',
  warehouseId: null,
  id: null,
  stocklnDate: '',
  reckonPieceDate: '',
  salesman: '',
  stockInTypeName: '',
  customName: '',
  carPlate: '',
  deliveryPerson: '',
  deliveryDepartmentName: '',
  deliveryDepartmentId: null,
  customOrderCode: '',
  processDepartment: '',
  carryTypeName: '',
  horseNum: 0,
  weight: 0,
  remark: '',
  deliveryCode: '',
  stockInCode: '',
  carryTypeId: '',
  BlankStockInDetail: [],

});
const pageData = reactive<{
  dutymachineState: any,
  sideTitle: string,
  showAdd8: boolean,
  pageLoading: boolean,
  rHeight: number,
  selsetionPrint: any,
  sourceCode: any,
  supplierName: any,
  customOrderCode: any,
  greyCode: any,
  brandName: any,
  customName: any,
  deliverySourceName: any,
  recordCode: any,
  dateStart: any,
  dateEnd: any,
  nameList: any[],
  nameList1: any[],
  nameList2: any[],
  nameList3: any[],
  nameList4: any[],
  nameListKW: any[],
}>({
  sideTitle: "新增入库单",
  dutymachineState: 0,
  showAdd8: false,
  pageLoading: false,
  rHeight: 0,
  selsetionPrint: '',
  sourceCode: '',
  supplierName: '',
  customOrderCode: '',
  greyCode: '',
  brandName: '',
  customName: '',
  deliverySourceName: '',
  recordCode: '',
  dateStart: '',
  dateEnd: '',
  nameList: [],
  nameList1: [],
  nameList2: [],
  nameList3: [],
  nameList4: [],
  nameListKW: [],
});
// 修改事件
const editHandler = (record: any) => {
  // console.log(record);
  for (var key in record) {
    objectOP[key] = record[key]
  }
  // console.log(objectOP.warehouseName, '1212121121');

  tableDataList1.value = []
  // 明细查询
  let list = gridOption3.value.getSelectedRows().map((item: any) => {
    return {stockInId: item.id}
  })
  post({
    url: "/dwWms/BlankStockInDetail/getList",
    // data: CCobject
    data: list[0]

  }).then((res: any) => {
    if (res.code === 200) {
      tableDataList3_2.value = res.data
    }
  })
  pageData.sideTitle = '修改入库单';
  pageData.showAdd8 = true;

}
// 织厂收货入库事件
const addHandler1 = (ress: any) => {
  if (gridOption.value.getSelectedRows().length === 0 || gridOption.value.getSelectedRows().length !== 1) {
    Message.error('勾选数据且只能勾选一条数据')
    return;
  } else {
    for (var key in objectOP) {
      if (key == "id") {
        objectOP[key] = null;

      } else {
        objectOP[key] = '';
      }
    }
    objectOP.reckonPieceDate = dayjs().format('YYYY-MM-DD')
    objectOP.stocklnDate = dayjs().format('YYYY-MM-DD')
    tableDataList1.value = []
    // 明细查询
    let list = gridOption.value.getSelectedRows().map((item: any) => {
      return {id: item.id}
    })
    post({
      url: "/dwWms/BlankStockIn/getGreyStockOutDetail",
      // data: CCobject
      data: list[0]

    }).then((res: any) => {
      if (res.code === 200) {
        tableDataList1.value = res.data
      }
    })
    gridOption.value.getSelectedRows().map((o: any) => {
      objectOP.customOrderCode = o.customOrderCode,
          objectOP.customName = o.customName,
          objectOP.carPlate = o.carPlate,
          objectOP.deliveryDepartmentName = o.deliveryDepartmentName,
          objectOP.deliveryDepartmentId = o.deliveryDepartmentId,
          objectOP.processDepartment = o.deliveryDepartmentName,
          objectOP.weight = o.weight,
          objectOP.horseNum = o.horseNum,
          objectOP.deliveryCode = o.stockOutCode
      objectOP.stockInTypeName = "织厂送货入库"
    })
    pageData.sideTitle = "新增织厂送货入库单";
    pageData.showAdd8 = true;
  }

}

const selectHandler = () => {
  if (tabsKeys.value == 1) {
    doRefresh()
  } else if (tabsKeys.value == 3) {
    doRefresh3()
  } else if (tabsKeys.value == 4) {
    doRefresh4()
  }
}
const addHandler = () => {
  if (tabsKeys.value == 1) {
    addHandler1(1)
  }
}

const tabsKeys = ref(1)

const tabsChanges = (e: any) => {
  tabsKeys.value = e
  if (e == 1) {
    toolbarList.value = ['查询', '入库']
  } else if (e == 3) {
    toolbarList.value = ['查询', '删除', '审核']
  } else if (e == 4) {
    toolbarList.value = ['查询', '打印']
  }
}


// 打印事件
const counters = (record: any) => {
  pageData.selsetionPrint = gridOption4.value.getSelectedRows()
  if (pageData.selsetionPrint.length == 0) {
    Message.error({
      content: '请选择您的单据',
      duration: 5000,
    })
    return
  }
  let condition = pageData.selsetionPrint.every(
      (item: any) => item.auditState == 0 || item.auditState == 2
  )
  if (condition) {
    Message.error({
      content: '状态未审核通过不可打印!',
      duration: 5000,
    })
    return
  }
  let ob = pageData.selsetionPrint.map((o: any) => {
    return o.id
  })
  post({
    url: '/dwWms/BlankStockIn/getStockInPrintPDF',
    data: ob,
    responseType: 'blob'
  }).then((res) => {
    let reader = new FileReader();
    reader.readAsDataURL(res);
    reader.onload = function () {
      let pdfBase64 = reader.result.replace('data:application/pdf;base64,', '');
      printJS({printable: pdfBase64, type: 'pdf', base64: true})
    };
  });
}
let stadey: boolean = true
const NO1 = () => {
  stadey = tableDataList1.value.every((item: any) => {
    return item.storageId
  })
}
const NO2 = () => {
  stadey = tableDataList1_2.value.every((item: any) => {
    return item.storageId && item.shelveId
  })
}
const NO3 = () => {
  stadey = tableDataList3_2.value.every((item: any) => {
    return item.storageId
  })
}
// 入库保存事件
const formRef = ref<FormInstance>();
const sideOk = () => {
  if (pageData.sideTitle == "新增织厂送货入库单") {
    NO1()
  } else if (pageData.sideTitle == "新增外加工入库单") {
    NO2()
  } else if (pageData.sideTitle == "修改入库单") {
    NO3()
  } else if (pageData.sideTitle == "新增车间退库") {
    stadey = true
  }
  if (stadey) {

    if (pageData.sideTitle !== '修改入库单') {
      objectOP.stockInCode = objectOP.deliveryCode
      if (objectOP.stockInTypeName === "织厂送货入库") {
        objectOP.stockInTypeId = 40
        tableDataList1.value.forEach((item: any) => {
          item.id = null
        })
        objectOP.BlankStockInDetail = tableDataList1.value
      } else if (objectOP.stockInTypeName === "外加工入库") {
        objectOP.stockInTypeId = 41
        tableDataList1_2.value.forEach((item: any) => {
          item.id = null
        })
        objectOP.BlankStockInDetail = tableDataList1_2.value
      } else {
        objectOP.stockInTypeId = 43
        tableDataList5_1.value.forEach((item: any) => {
          item.id = null
        })
        objectOP.BlankStockInDetail = tableDataList5_1.value
      }
      // if (pageData.sideTitle === "新增织厂送货入库单") {
      post({
        url: "/dwWms/BlankStockIn/insertList",
        data: objectOP
      }).then((res: any) => {
        if (res.code === 200) {
          formRef.value?.resetFields();
          pageData.showAdd8 = false;
          Message.success({
            content: "新增成功",
            duration: 5000,
          });
          doRefresh();
        } else {
          Message.error({
            content: res.message,
            duration: 5000,
          });
        }
      })
    } else {
      objectOP.BlankStockInDetail = tableDataList3_2.value
      post({
        url: "/dwWms/BlankStockIn/updateList",
        data: objectOP
      }).then((res: any) => {
        if (res.code === 200) {
          formRef.value?.resetFields();
          pageData.showAdd8 = false;
          Message.success({
            content: "修改成功",
            duration: 5000,
          });
          doRefresh();
        } else {
          Message.error({
            content: res.message,
            duration: 5000,
          });
        }
      })
    }

  } else {
    Message.error({
      content: '请完整填写库位(不可遗漏)！',
      duration: 5000,
    });
    return
  }

}
// 仓库名称下拉框下拉数据
const focusSel = () => {
  selCxAll({"firmId": "", warehouseTypeName: "毛坯仓"});
}
const options = ref<any>(pageData.nameList);
const loading = ref(false);
const handleSearch = (value: any) => {
  if (value) {
    const ob = {firmId: value, deleteState: 0, warehouseTypeName: "毛坯仓"}
    loading.value = true;
    selCxAll(ob);
    options.value = pageData.nameList;
    loading.value = false;
  } else {
    options.value = []
  }
};

function selCxAll(val: any) {
  let ob = ''
  // if (pageData.sideTitle == '新增织厂送货入库单') {
  ob = gridOption.value.getSelectedRows().map((item: any) => {
    return item.companyId
  })
  objectOP.companyId = ob[0]
  // console.log(ob, '多年以后我看着泪流不止');
  // } else {
  //     ob = gridOption2.value.getSelectedRows().map((item: any) => {
  //         return item.companyId
  //     })
  //     objectOP.companyId = ob[0]
  //     // console.log(ob, '我的父亲已经老得像一张旧报纸');
  // }


  post({
    url: "/dwWms/warehouse/getWarehouseByPara",
    data: {firmId: ob[0], warehouseTypeName: "毛坯仓"}
  }).then(({data, code}: any) => {
    if (code === 200) {
      pageData.nameList = data;
    } else {
      Message.error({
        content: "查询失败！",
        duration: 5000,
      });
    }
  });
}

const chanON = (res: any) => {
  pageData.nameList.forEach((o: any) => {
    if (objectOP.warehouseName == o.name) {
      return objectOP.warehouseId = o.id
    }
  })
}
// 业务员下拉框下拉数据
const focusSel1 = () => {
  selCxAll1({"name": ""});
}
const options1 = ref<any>(pageData.nameList1);
const loading1 = ref(false);
const handleSearch1 = (value: any) => {
  if (value) {
    const ob = {name: value, deleteState: 0}
    loading1.value = true;
    selCxAll1(ob);
    options1.value = pageData.nameList1;
    loading1.value = false;
  } else {
    options1.value = []
  }
};

function selCxAll1(val: any) {
  post({
    url: "/org/hrEmployee/getList",
    data: val
  }).then(({data, code}: any) => {
    if (code === 200) {
      pageData.nameList1 = data;
    } else {
      Message.error({
        content: "查询失败！",
        duration: 5000,
      });
    }
  });
}

// 搬运方式下拉框下拉数据
const focusSel4 = () => {
  post({
    url: "dwPc/WarehousePiece/getList",
    data: {}
  }).then(({data, code}: any) => {
    if (code === 200) {
      pageData.nameList4 = data;
    } else {
      Message.error({
        content: "查询失败！",
        duration: 5000,
      });
    }
  });
}
const change4 = (item: any) => {
  // console.log(item, 'aaaaaaaaaaaaa');
  pageData.nameList4.forEach((o: any) => {
    if (item == o.carryTypeName) {
      objectOP.carryTypeId = o.id
    }
  })
}


// 未审核页面审核方法
const audits = () => {
  if (gridOption3.value.getSelectedRows().length === 0) {
    Message.error('请先勾选')
    return;
  }
  Modal.confirm({
    title: '系统提示',
    content: '是否审核此订单',
    onOk() {
      post({
        url: "/dwWms/BlankStockIn/setAudit",
        // data: auditStateId,
        data: gridOption3.value.getSelectedRows().map((item: any) => {
          return {id: item.id, auditState: 1}
        })
      }).then((res: any) => {
        if (res.code === 200) {
          doRefresh3();
          Message.success('审核通过')
          // selectedRowKeys.value = []
        } else {
          Message.error(res.message)
        }
      })
    }
  })
}
// 删除事件
const deleteHandler = () => {
  if (gridOption3.value.getSelectedRows().length === 0) {
    Message.error('请先勾选')
    return;
  }
  Modal.confirm({
    title: "系统提示",
    content: "确认删除选中的数据?",
    onOk() {
      post({
        url: "/dwWms/BlankStockIn/delete",
        data: gridOption3.value.getSelectedRows().map((o: any) => {
          return o.id
        })
      }).then(({code, data, message}: any) => {
        if (code === 200) {
          Message.success({
            content: "删除成功",
            duration: 5000,
          });

          pagination.page = 1
          doRefresh3();

        } else {
          Message.error({
            content: '删除失败',
            duration: 5000,
          });
        }

      });
    },
  });
};
// 织厂收货查询事件
const total = ref(10);
const total1 = ref(10);
const total3 = ref(10);
const total4 = ref(10);
const total5 = ref(10);
const pagingList1: any = ref(pagingList)
const page = ref(1);
const size = ref(10);

function doRefresh() {
  pageData.pageLoading = true
  post({
    url: "/dwWms/BlankStockIn/getGreyStockOutDataLink",
    data: {
      stockOutTypeId: 33,
      page: pagination.page,
      size: pagination.pageSize,
      sourceCode: pageData.sourceCode,
      customName: pageData.customName,
      dateStart: pageData.dateStart,
      dateEnd: pageData.dateEnd,
      deleteState: 0,
    },
  })
      .then(({data, code}: any) => {
        if (code === 200) {

          table.handleSuccess(data.list);
          gridOption.value.setRowData(data.list)
          total.value = data.total;

        }
      })
      .catch(console.log).finally(() => {
    pageData.pageLoading = false
  })
}

// 未审核查询事件
function doRefresh3() {
  pageData.pageLoading = true
  post({
    url: "/dwWms/BlankStockIn/getPage",
    data: {
      page: pagination.page,
      size: pagination.pageSize,
      sourceCode: pageData.sourceCode,
      supplierName: pageData.supplierName,
      customName: pageData.customName,
      dateStart: pageData.dateStart,
      dateEnd: pageData.dateEnd,
      deleteState: 0,
      auditState: 0
    },
  })
      .then(({data, code}: any) => {
        if (code === 200) {

          table.handleSuccess(data.list);
          gridOption3.value.setRowData(data.list)
          total3.value = data.total;

        }
      })
      .catch(console.log).finally(() => {
    pageData.pageLoading = false
  })
}

// 已审核查询事件
function doRefresh4() {
  pageData.pageLoading = true
  post({
    url: "/dwWms/BlankStockIn/getPage",
    data: {
      page: pagination.page,
      size: pagination.pageSize,
      sourceCode: pageData.sourceCode,
      supplierName: pageData.supplierName,
      customName: pageData.customName,
      dateStart: pageData.dateStart,
      dateEnd: pageData.dateEnd,
      deleteState: 0,
      auditState: 1
    },
  })
      .then(({data, code}: any) => {
        if (code === 200) {

          table.handleSuccess(data.list);
          gridOption4.value.setRowData(data.list)
          total4.value = data.total;

        }
      })
      .catch(console.log).finally(() => {
    pageData.pageLoading = false
  })
}

const {selectedRowKeys, onSelectionChange} = useRowSelection();
const pagination = usePagination(doRefresh);
const pagination3 = usePagination(doRefresh3);
const pagination4 = usePagination(doRefresh4);
const table = useTable();
const rowKey = useRowKey("id");

const prints2 = () => {
  console.log(gridOption3.value.getSelectedRows());

}
</script>
<script lang="ts">
export default {
  name: "MaopiRuku",
}
</script>
<style scoped lang="less">
:deep(.ag-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-cell-value) {
  user-select: initial;
  -moz-user-select: text;
  -ms-user-select: text;
  -webkit-user-select: text;
}

.DivFit {
  width: 100%;
  height: 20px;
  margin-left: 20px;
}

.DivFit div {
  float: left;
  width: 200px;
}

.isTable1 {
  margin: 50px;
  width: 90%;
  // margin: 0 auto;
  border: 1.2px solid #ccc;
  text-align: center;
  border-collapse: collapse;

  td {
    border: 1.2px solid #ccc;
  }

  th {
    border: 1.2px solid #ccc;
  }
}
</style>
